<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>发布电影页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../static/css/font.css">
		<link rel="stylesheet" href="../../../static/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="weadmin-body">
        <form class="layui-form" action="/admin/film/edit" method="post">
             <!-- 电影海报 -->
             <div class="layui-form-item">
                <label for="filmName" class="layui-form-label">
                    <span class="we-red">*</span>电影海报
                </label>
                <div class="layui-input-inline">
                    <img style="width: 150px;height: 150px;" id="poster_img" src="<%-film.poster%>" alt="">
                </div>
            </div>
            <!-- 电影海报上传 -->
            <div class="layui-form-item">
                <label for="filmName" class="layui-form-label">
                    <span class="we-red">*</span>海报上传
                    <input type="text" id="img_h" name="img_h" hidden>
                </label>
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn" id="poster">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                      </button>
                </div>
            </div>
         <!-- 电影名 -->
            <div class="layui-form-item">
              <label for="filmName" class="layui-form-label">
                  <span class="we-red">*</span>电影名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="filmName" name="filmName" class="layui-input" value="<%-film.filmName%>">
              </div>
          </div>
          <!-- 电影类型 -->
          <div class="layui-form-item">
            <label for="teype" class="layui-form-label">
                <span class="we-red">*</span>电影类型
            </label>
            <div class="layui-input-inline">
                <select name="typeid" lay-filter="aihao">
                <%
                for(i=0;i<type.length;i++){%>
                        <option value="<%-type[i].id%>" <% if(type[i].id == film.Typeid){ %>
                            selected="true"
                            <%}%>
                            >
                            <%-type[i].typeName%></option>
                <%}%>
            </select>
            </div>
         </div>
         <!-- 导演 -->
         <div class="layui-form-item">
            <label for="" class="layui-form-label">
                <span class="we-red">*</span>导演
            </label>
            <div class="layui-input-inline">
                <input type="text" id="director" name="director" class="layui-input" value="<%-film.director%>">
            </div>
         </div>
            <!-- 地区 -->
            <div class="layui-form-item">
                <label for="" class="layui-form-label">
                    <span class="we-red">*</span>地区
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="region" name="region" class="layui-input" value="<%-film.region%>">
                </div>
            </div>
            <!-- 年代 -->
            <div class="layui-form-item">
                <label for="" class="layui-form-label">
                    <span class="we-red">*</span>年代
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="year" name="year" class="layui-input" value="<%-film.year%>">
                </div>
            </div>
            <!-- 电影下载地址 -->
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="we-red">*</span>连接地址
                </label>
                  <div class="layui-input-block">
                    <input type="text" autocomplete="off" class="layui-input" id="movieUrl" name="movieUrl" value="<%-film.movieUrl%>"  placeholder="请输入URL地址">
                  </div>
            </div>
            <!-- 电影简介 -->
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="we-red">*</span>电影简介
                </label>
                  <div class="layui-input-block">
                    <textarea name="brief" id="brief" cols="60" rows="10" style="resize:none"><%-film.brief%></textarea>
                    <!-- <input type="text" autocomplete="off" class="layui-input" id="brief" name="brief" value="<%-film.brief%>"  placeholder="请输电影简介"> -->
                  </div>
            </div>
            <!-- 电影id -->
            <div class="layui-form-item" hidden>
                <label for="username" class="layui-form-label">
                </label>
                  <div class="layui-input-block">
                    <input type="text" class="layui-input" id="fid" name="fid" value="<%-film.id%>" disabled>
                  </div>
            </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="add">
                  发布电影
              </button>
          </div>
      </form>
    </div>
        <script src="../../../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript">
    	layui.extend({
				admin: '{/}../../../static/js/admin'
			});
	    layui.use(['form','layer','admin','jquery','upload'], function(){
	      var form = layui.form,
	      admin = layui.admin,
	      layer = layui.layer;
          var $ = layui.jquery;
          var upload = layui.upload;
        //验证输入的内容是否已存在

          //监听提交
          form.on('submit(add)', function(data){
            console.log(data);
            $.ajax({
              url:"/admin/film/edit",
              method:"post",
              data:data.field
            }).then(function(res){ //提交后
            //     layer.msg('同上', {
            //    icon: 1,
            //   time: 2000 //2秒关闭（如果不配置，默认是3秒）
            // },
              //发异步，把数据提交给nodejs
            layer.alert("修改成功", {icon: 6},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
                //添加成功后刷新页面
                parent.location.reload();
            });
            })
            return false;
          });
         //文件上传
        var uploadInst = upload.render({
            elem: '#poster' //绑定元素
            ,url: '/admin/film/edit/poster' //上传接口
            ,field:"poster"
            // ,acceptMime:'image/jpg,image/png'   //打开选择框是只显示后缀名为一下的文件
            ,done: function(res){
                //上传完毕回调
                $('#poster_img').attr('src',res.imgUrl)
                $('#img_h').val(res.imgUrl)
            }
            ,error: function(){
                //请求异常回调
            }
        });

        });
    </script>
  </body>

</html>